package admin

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"strings"
	"time"
	"zhuandan/data_source"
	"zhuandan/models"
	"zhuandan/utils"
)

type Infouser struct {
	Data       []models.User `json:"data"`
	PageNo     int           `json:"pageNo"`
	PageSize   int           `json:"pageSize"`
	TotalCount int64         `json:"totalCount"`
	TotalPage  int64         `json:"totalPage"`
}

type UserlistBody struct {
	Page       int    `json:"pageNo" from:"pageNo"`
	Pagesize   int    `json:"pageSize" from:"pageSize"`
	Phone      string `json:"phone" from:"phone"`
	Vip        int64  `json:"vip" from:"vip"`
	Status     int64  `gorm:"column:status" json:"status"`
	Modelphone int64  `gorm:"column:modelphone" json:"modelphone"`
	Fadan      int64  `gorm:"column:fadan" json:"fadan"`
	Nickname   string `gorm:"column:nickname" json:"nickname"`

	CreateTime      int64   `gorm:"column:create_time" json:"create_time"`
	LoginNum        int64   `gorm:"column:login_num" json:"login_num"`
	Adminid         int64   `gorm:"column:adminid" json:"adminid"`
	Jingli          string  `gorm:"column:jingli" json:"jingli"`
	Gzh             int64   `gorm:"column:gzh" json:"gzh"`
	Dkh             int64   `gorm:"column:dkh" json:"dkh"`
	Maxprice        float64 `gorm:"column:maxprice" json:"maxprice"`
	Minprice        float64 `gorm:"column:minprice" json:"minprice"`
	Xiaoshoutuiguan int64   `json:"xiaoshoutuiguan" gorm:"xiaoshoutuiguan"`
}

func Userlist(ctx *gin.Context) {
	request := UserlistBody{}
	ctx.ShouldBind(&request)
	phone := request.Phone
	maxprice := request.Maxprice
	xiaoshoutuiguan := request.Xiaoshoutuiguan
	gzh := request.Gzh
	dkh := request.Dkh
	create_time := request.CreateTime
	login_num := request.LoginNum
	vip := request.Vip
	adminid := request.Adminid
	nickname := request.Nickname
	status := request.Status
	modelphone := request.Modelphone
	currentPage := request.Page
	pageSize := request.Pagesize
	fadan := request.Fadan
	jingli := request.Jingli
	offsetNum := pageSize * (currentPage - 1)
	var count int64
	var users []models.User
	res := data_source.Db
	if gzh > 0 {
		if gzh == 1 {
			res = res.Where("routine_openid != ?", "")
		} else if gzh == 2 {
			res = res.Where("ywdgzheopenid != ?", "")
		} else if gzh == 3 {
			res = res.Where("ywdopenid != ?", "")
		}
	}
	if dkh > 0 {
		if dkh == 2 {
			res = res.Where("bnendtime > ?", time.Now().Unix())
		}
	}
	if fadan > 0 {
		res = res.Where("identity = ?", fadan)
	}
	if maxprice > 0 {
		res = res.Where("price < ?", maxprice)
	}
	if maxprice > 0 {
		res = res.Where("price < ?", maxprice)
	}
	if xiaoshoutuiguan > 0 {
		res = res.Where("xiaoshoutuiguan = ?", xiaoshoutuiguan)
	}
	if nickname != "" {
		res = res.Where("nickname like ?", "%"+nickname+"%")
	}
	if phone != "" {
		res = res.Where("phone = ?", phone)
	}
	if jingli != "" {
		res = res.Where("jingli = ?", jingli)
	}
	if vip > 0 {
		res = res.Where("vip = ?", vip)
	}
	if status > 0 {
		res = res.Where("status = ?", status)
	}
	if modelphone > 0 {
		res = res.Where("modelphone = ?", modelphone)
	}
	if login_num > 0 {
		endlogintime := login_num + 86400
		res = res.Where("login_num > ? and login_num < ?", login_num, endlogintime)
	}
	if create_time > 0 {
		endcreatetime := create_time + 86400
		res = res.Where("create_time > ? and create_time < ?", create_time, endcreatetime)
	}
	res.Model(&models.User{}).Count(&count)
	res.Limit(pageSize).Offset(offsetNum).Order("id desc").Find(&users)
	for k, v := range users {
		if v.Bnendtime > time.Now().Unix() {
			users[k].Dakefu = 2
		} else {
			users[k].Dakefu = 1
		}
	}
	var totalPage int64
	mo := count % int64(pageSize)
	if mo > 0 {
		totalPage = count/int64(pageSize) + 1
	} else {
		totalPage = count / int64(pageSize)
	}
	data := Infouser{
		Data:       users,
		PageNo:     currentPage,
		PageSize:   pageSize,
		TotalCount: count,
		TotalPage:  totalPage,
	}
	if adminid > 0 {
		adminlog := models.Adminlog{
			Adminid: adminid,
			Addtime: time.Now().Unix(),
			Content: "查看用户列表",
		}
		data_source.Db.Create(&adminlog)
	}
	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    data,
		"msg":     "ok",
	})
	return

}

type UserupdateBody struct {
	ID              int64   `gorm:"column:id" json:"id"`
	Status          int64   `gorm:"column:status" json:"status"`
	Vippackageid    int64   `gorm:"column:vippackageid" json:"vippackageid"`
	Beizhu          string  `gorm:"column:beizhu" json:"beizhu"`
	Yesxf           float64 `gorm:"column:yesxf" json:"yesxf"`
	Tgsxf           float64 `gorm:"column:tgsxf" json:"tgsxf"`
	Adminid         int64   `gorm:"column:adminid" json:"adminid"`
	Chongzhi        int64   `gorm:"column:chongzhi" json:"chongzhi"`
	Jingli          string  `gorm:"column:jingli" json:"jingli"`
	Phone           string  `gorm:"column:phone" json:"phone"`
	Identity        int64   `gorm:"column:identity" json:"identity"`
	Xiaoshou        int64   `gorm:"column:xiaoshou" json:"xiaoshou"`
	Jingliname      string  `gorm:"column:jingliname" json:"jingliname"`
	Vip             int64   `gorm:"column:vip" json:"vip"`
	Vipinttime      int64   `gorm:"column:vipinttime" json:"vipinttime"`
	Vipendtime      int64   `gorm:"column:vipendtime" json:"vipendtime"`
	State           int64   `gorm:"column:state" json:"state"`
	Dakefu          int64   `gorm:"column:dakefu" json:"dakefu"`
	Xiaoshoutuiguan int64   `json:"xiaoshoutuiguan" gorm:"xiaoshoutuiguan"`
}

func UserDakefuup(ctx *gin.Context) {
	request := UserupdateBody{}
	ctx.ShouldBind(&request)
	id := request.ID
	dakefu := request.Dakefu
	data_source.Db.Model(&models.User{}).Where("id = ?", id).Update("dakefu", dakefu)

	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return
}
func Useridentity(ctx *gin.Context) {
	request := UserupdateBody{}
	ctx.ShouldBind(&request)
	id := request.ID
	identity := request.Identity
	data_source.Db.Model(&models.User{}).Where("id = ?", id).Update("identity", identity)

	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return

}
func Userxstg(ctx *gin.Context) {
	request := UserupdateBody{}
	ctx.ShouldBind(&request)
	id := request.ID
	xiaoshoutuiguan := request.Xiaoshoutuiguan
	data_source.Db.Model(&models.User{}).Where("id = ?", id).Update("xiaoshoutuiguan", xiaoshoutuiguan)

	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return
}
func Userchongzhi(ctx *gin.Context) {
	request := UserupdateBody{}
	ctx.ShouldBind(&request)
	id := request.ID
	chongzhi := request.Chongzhi
	data_source.Db.Model(&models.User{}).Where("id = ?", id).Update("chongzhi", chongzhi)

	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return

}
func Userupdate(ctx *gin.Context) {
	request := UserupdateBody{}
	ctx.ShouldBind(&request)
	id := request.ID
	status := request.Status
	data_source.Db.Model(&models.User{}).Where("id = ?", id).Update("status", status)

	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return

}
func Userxiaoshou(ctx *gin.Context) {
	request := UserupdateBody{}
	ctx.ShouldBind(&request)
	id := request.ID
	xiaoshou := request.Xiaoshou
	data_source.Db.Model(&models.User{}).Where("id = ?", id).Update("xiaoshou", xiaoshou)

	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return

}

func Userupdatejingli(ctx *gin.Context) {
	request := UserupdateBody{}
	ctx.ShouldBind(&request)
	id := request.ID
	jingli := request.Jingli
	jingliname := request.Jingliname
	userupdate := models.User{
		Jingliname: jingliname,
		Jingli:     jingli,
	}
	data_source.Db.Where("id = ?", id).Updates(&userupdate)

	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return

}

func Userupdatetx(ctx *gin.Context) {
	request := UserupdateBody{}
	ctx.ShouldBind(&request)
	id := request.ID
	yesxf := request.Yesxf
	tgsxf := request.Tgsxf
	adminid := request.Adminid
	userup := models.User{
		Yesxf: yesxf,
		Tgsxf: tgsxf,
	}
	data_source.Db.Where("id = ?", id).Updates(&userup)

	if adminid > 0 {
		adminlog := models.Adminlog{
			Adminid: adminid,
			Addtime: time.Now().Unix(),
			Content: "修改用户提现比例",
		}
		data_source.Db.Create(&adminlog)
	}

	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return

}

func Userupdatepid(ctx *gin.Context) {
	request := UserupdateBody{}
	ctx.ShouldBind(&request)
	id := request.ID
	phone := request.Phone
	var user models.User
	data_source.Db.Where("phone = ?", phone).First(&user)

	if user.ID == 0 {
		ctx.JSON(http.StatusOK, gin.H{
			"code":    400,
			"error":   1,
			"success": 0,
			"msg":     "该手机号不存在",
			"data":    "on",
		})
		return
	}
	data_source.Db.Model(&models.User{}).Where("id = ?", id).Update("pid", user.ID)
	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return

}

func Userbeizhu(ctx *gin.Context) {
	request := UserupdateBody{}
	ctx.ShouldBind(&request)
	id := request.ID
	beizhu := request.Beizhu
	data_source.Db.Model(&models.User{}).Where("id = ?", id).Update("beizhu", beizhu)
	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return

}

func Userphone(ctx *gin.Context) {
	request := UserupdateBody{}
	ctx.ShouldBind(&request)
	id := request.ID
	phone := request.Phone
	data_source.Db.Model(&models.User{}).Where("id = ?", id).Update("phone", phone)
	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return

}

func Userupdateinfo(ctx *gin.Context) {
	request := UserupdateBody{}
	ctx.ShouldBind(&request)
	id := request.ID
	beizhu := request.Beizhu
	data_source.Db.Model(&models.User{}).Where("id = ?", id).Update("beizhu", beizhu)

	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return

}

type UserpricelistRBody struct {
	Data       []models.Userpricenewsql `json:"data"`
	PageNo     int                      `json:"pageNo"`
	PageSize   int                      `json:"pageSize"`
	TotalCount int64                    `json:"totalCount"`
	TotalPage  int64                    `json:"totalPage"`
}

type UserpricelistBody struct {
	Page     int     `json:"pageNo" from:"pageNo"`
	Pagesize int     `json:"pageSize" from:"pageSize"`
	Uid      int64   `json:"uid" from:"uid"`
	State    int64   `json:"state" from:"state"`
	Price    float64 `json:"price" from:"price"`
	Phone    string  `json:"phone" from:"phone"`
	Nickname string  `json:"nickname" from:"nickname"`
	Adminid  int64   `json:"adminid" from:"adminid"`
	Title    string  `json:"title" from:"title"`
}

func Userpricelist(ctx *gin.Context) {
	request := UserpricelistBody{}
	ctx.ShouldBind(&request)
	uid := request.Uid
	state := request.State
	phone := request.Phone
	nickname := request.Nickname

	currentPage := request.Page
	pageSize := request.Pagesize

	offsetNum := pageSize * (currentPage - 1)
	var count int64
	var users []models.Userpricenewsql
	res := data_source.Db.Model(&models.Userpricenew{}).Select("userpricenew.*, user.nickname,  user.phone").Joins("left join user on user.id = userpricenew.uid")
	if uid > 0 {
		res = res.Where("userpricenew.uid = ?", uid)
	}
	if state > 0 {
		res = res.Where("userpricenew.state = ?", state)
	}
	if nickname != "" {
		res = res.Where("user.nickname like ?", "%"+nickname+"%")
	}
	if phone != "" {
		res = res.Where("user.phone = ?", phone)
	}
	res.Model(&models.Userpricenew{}).Count(&count)
	res.Limit(pageSize).Offset(offsetNum).Order("userpricenew.addtime desc").Find(&users)
	var totalPage int64
	mo := count % int64(pageSize)
	if mo > 0 {
		totalPage = count/int64(pageSize) + 1
	} else {
		totalPage = count / int64(pageSize)
	}
	data := UserpricelistRBody{
		Data:       users,
		PageNo:     currentPage,
		PageSize:   pageSize,
		TotalCount: count,
		TotalPage:  totalPage,
	}
	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    data,
		"msg":     "ok",
	})
	return

}

type UsertixianlistRBody struct {
	Data       []models.Userpricesql `json:"data"`
	PageNo     int                   `json:"pageNo"`
	PageSize   int                   `json:"pageSize"`
	TotalCount int64                 `json:"totalCount"`
	TotalPage  int64                 `json:"totalPage"`
}

func Usertixianlist(ctx *gin.Context) {
	request := UserpricelistBody{}
	ctx.ShouldBind(&request)
	uid := request.Uid
	state := request.State
	phone := request.Phone
	nickname := request.Nickname
	title := request.Title

	currentPage := request.Page
	pageSize := request.Pagesize

	offsetNum := pageSize * (currentPage - 1)
	var count int64
	var users []models.Userpricesql
	res := data_source.Db.Model(&models.Userprice{}).Select("userprice.*, user.nickname,  user.phone").Joins("left join user on user.id = userprice.uid")
	if uid > 0 {
		res = res.Where("userprice.uid = ?", uid)
	}
	if state > 0 {
		res = res.Where("userprice.state = ?", state)
	}
	if nickname != "" {
		res = res.Where("user.nickname like ?", "%"+nickname+"%")
	}
	if title != "" {
		res = res.Where("userprice.title like ?", "%"+title+"%")
	}
	if phone != "" {
		res = res.Where("user.phone = ?", phone)
	}
	res.Model(&models.Userprice{}).Count(&count)
	res.Limit(pageSize).Offset(offsetNum).Order("userprice.addtime desc").Find(&users)
	var totalPage int64
	mo := count % int64(pageSize)
	if mo > 0 {
		totalPage = count/int64(pageSize) + 1
	} else {
		totalPage = count / int64(pageSize)
	}
	data := UsertixianlistRBody{
		Data:       users,
		PageNo:     currentPage,
		PageSize:   pageSize,
		TotalCount: count,
		TotalPage:  totalPage,
	}
	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    data,
		"msg":     "ok",
	})
	return

}
func Userpriceupdate(ctx *gin.Context) {
	request := UserpricelistBody{}
	ctx.ShouldBind(&request)
	uid := request.Uid
	state := request.State
	price := request.Price
	adminid := request.Adminid
	title := request.Title

	if price < 0 {
		ctx.JSON(http.StatusOK, gin.H{
			"code":    400,
			"error":   1,
			"success": 400,
			"data":    "on",
			"msg":     "请输入正确金额",
		})
		return
	}

	var user models.User
	data_source.Db.Where("id = ?", uid).First(&user)
	if state == 1 {
		userpricenew := models.Userpricenew{
			Uid:     uid,
			Addtime: time.Now().Unix(),
			State:   1,
			Price:   price,
			Title:   title + "后台增加余额，充值人id：" + utils.Int64string(adminid),
			Dqprice: user.Price + price,
		}
		data_source.Db.Create(&userpricenew)
		data_source.Db.Model(&models.User{}).Where("id = ?", uid).Update("price", user.Price+price)
		if adminid > 0 {
			adminlog := models.Adminlog{
				Adminid: adminid,
				Addtime: time.Now().Unix(),
				Content: "给用户充值，用户id：" + utils.Int64string(uid),
			}
			data_source.Db.Create(&adminlog)
		}
	} else {
		if price > user.Price {
			ctx.JSON(http.StatusOK, gin.H{
				"code":    400,
				"error":   1,
				"success": 400,
				"data":    "on",
				"msg":     "减少金额不能大于当前余额",
			})
			return
		}
		userpricenew := models.Userpricenew{
			Uid:     uid,
			Addtime: time.Now().Unix(),
			State:   2,
			Price:   price,
			Title:   title + "后台减少余额，充值人id：" + utils.Int64string(adminid),
			Dqprice: user.Price - price,
		}
		data_source.Db.Create(&userpricenew)
		data_source.Db.Model(&models.User{}).Where("id = ?", uid).Update("price", user.Price-price)
		if adminid > 0 {
			adminlog := models.Adminlog{
				Adminid: adminid,
				Addtime: time.Now().Unix(),
				Content: "给减少余额，用户id：" + utils.Int64string(uid),
			}
			data_source.Db.Create(&adminlog)
		}
	}
	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return

}

func Userts(ctx *gin.Context) {
	request := UsertsBody{}
	ctx.ShouldBind(&request)
	id := request.ID
	provincecodes := request.Provincecodes
	classifyids := request.Classifyids
	dcbuy := request.Dcbuy
	user := models.User{
		Provincecodes: provincecodes,
		Classifyids:   classifyids,
		Dcbuy:         dcbuy,
	}
	data_source.Db.Where("id = ?", id).Updates(&user)

	provinceidarr := strings.Split(provincecodes, ",")
	classifyidarr := strings.Split(classifyids, ",")

	data_source.Db.Where("uid = ?", id).Where("state = 1").Delete(&models.Tuisongshezhi{})
	var tuisongshezhis []models.Tuisongshezhi
	for _, p := range provinceidarr {
		for _, c := range classifyidarr {
			tuisongshezhi := models.Tuisongshezhi{
				Uid:        id,
				Provinceid: utils.StrToInt64(p),
				Classifyid: utils.StrToInt64(c),
				State:      1,
			}
			tuisongshezhis = append(tuisongshezhis, tuisongshezhi)
		}
	}
	data_source.Db.Create(&tuisongshezhis)

	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return

}

func Userbn(ctx *gin.Context) {
	request := UsertsBody{}
	ctx.ShouldBind(&request)
	id := request.ID
	provincecodes := request.Provincecodes
	classifyids := request.Classifyids
	bninttime := request.Bninttime
	bnendtime := request.Bnendtime
	user := models.User{
		Bnprovincecodes: provincecodes,
		Bnclassifyids:   classifyids,
		Bnendtime:       bnendtime,
		Bninttime:       bninttime,
	}
	data_source.Db.Where("id = ?", id).Updates(&user)

	provinceidarr := strings.Split(provincecodes, ",")
	classifyidarr := strings.Split(classifyids, ",")

	data_source.Db.Where("uid = ?", id).Delete(&models.Baonian{})
	var tuisongshezhis []models.Baonian
	for _, p := range provinceidarr {
		for _, c := range classifyidarr {
			tuisongshezhi := models.Baonian{
				Uid:        id,
				Provinceid: utils.StrToInt64(p),
				Classifyid: utils.StrToInt64(c),
			}
			tuisongshezhis = append(tuisongshezhis, tuisongshezhi)
		}
	}
	data_source.Db.Create(&tuisongshezhis)

	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return

}

type UsertsBody struct {
	ID            int64  `json:"id" from:"id"`
	Provincecodes string `gorm:"column:provincecodes" json:"provincecodes"`
	Classifyids   string `gorm:"column:classifyids" json:"classifyids"`
	Bninttime     int64  `gorm:"column:bninttime" json:"bninttime"`
	Bnendtime     int64  `gorm:"column:bnendtime" json:"bnendtime"`
	State         int64  `gorm:"column:state" json:"state"`
	Guanzhu       int64  `gorm:"column:guanzhu" json:"guanzhu"`
	Vipbeizhu     string `gorm:"column:vipbeizhu" json:"vipbeizhu"`
	Year          int64  `gorm:"column:year" json:"year"`
	Bangwowa      int64  `gorm:"column:bangwowa" json:"bangwowa"`
	Dcbuy         int64  `json:"dcbuy" gorm:"dcbuy"`
}

func Userbangwowa(ctx *gin.Context) {
	request := UsertsBody{}
	ctx.ShouldBind(&request)
	id := request.ID
	bangwowa := request.Bangwowa

	user := models.User{
		Bangwowa: bangwowa,
	}
	data_source.Db.Where("id = ?", id).Updates(&user)
	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return

}
func Uservipkt(ctx *gin.Context) {
	request := UsertsBody{}
	ctx.ShouldBind(&request)
	id := request.ID
	vipbeizhu := request.Vipbeizhu
	year := request.Year
	inttime := time.Now().Unix()
	user := models.User{
		Vip:        2,
		Vipbeizhu:  vipbeizhu,
		Vipinttime: inttime,
		Vipendtime: inttime + year*365*86400,
	}
	data_source.Db.Where("id = ?", id).Updates(&user)
	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return
}

func Userguanzhu(ctx *gin.Context) {
	request := UsertsBody{}
	ctx.ShouldBind(&request)
	id := request.ID
	guanzhu := request.Guanzhu

	user := models.User{
		Guanzhu: guanzhu,
	}
	data_source.Db.Where("id = ?", id).Updates(&user)
	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return

}
func Userstate(ctx *gin.Context) {
	request := UsertsBody{}
	ctx.ShouldBind(&request)
	id := request.ID
	state := request.State

	user := models.User{
		State: state,
	}
	data_source.Db.Where("id = ?", id).Updates(&user)
	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return

}
